from langchain_core.messages import HumanMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

from com.wp.langchain.simpleDemo.LLMInit import LLMInit

model = LLMInit().get_llm()
# 稍微改变了输入类型 - 我们现在传递的是一个包含 messages 键的字典，其中包含一系列消息，而不是传递消息列表。
prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant. Answer all questions to the best of your ability.",
        ),
        MessagesPlaceholder(variable_name="messages"),
    ]
)

chain = prompt | model

invoke = chain.invoke({"messages": [HumanMessage(content="hi! I'm bob")]})
print(invoke.content)


prompt1 = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant. Answer all questions to the best of your ability in {language}.",
        ),
        MessagesPlaceholder(variable_name="messages"),
    ]
)

chain1 = prompt1 | model
invoke1 = chain1.invoke({"messages": [HumanMessage(content="hi! I'm bob")], "language": "Chinese"})
print(invoke1.content)
